<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电灯开关练习案例</title>
</head>
<body>
    <img src="image/off.gif" alt="电灯" id="light">
<script>
    var flag = false ; // 电灯关状态
    function controll () {
        var light = document.getElementById("light");
        if (flag) {
            light.src = "image/off.gif";
            flag = false;
        } else {
            light.src = "image/on.gif";
            flag = true;
        }
    }


    light.onclick = controll;
</script>
</body>
</html>